package com.song.estore.dao;

import com.song.estore.domain.Product;
import org.hibernate.Session;
import org.hibernate.SessionFactory;


public class ProductDao {
	private SessionFactory sessionFactory;


	private Session getSession(){
		return sessionFactory.getCurrentSession();
	}

	public int addProduct(Product pro) {

		return getSession().createSQLQuery("INSERT INTO " +
				"product(name, category, marketprice, estoreprice, pnum, imgurl, description)  " +
				"VALUES (?,?,?,?,?,?,?)")
				.setString(0, pro.getName())
				.setString(1, pro.getCategory())
				.setDouble(2, pro.getMarketprice())
				.setDouble(3, pro.getEstoreprice())
				.setInteger(4, pro.getPnum())
				.setString(5, pro.getImgurl())
				.setString(6, pro.getDescription()).executeUpdate();

	}

	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}
}
